<?php

namespace app\admin\service;


use app\admin\model\GiftRecord;
use think\facade\Db;

/**
 * 用户转增经书记录管理-服务类
 * @author 小树林
 * @since: 2024/11/22
 * Class GiftRecordService
 * @package app\admin\service
 */
class GiftRecordService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new GiftRecord();
    }

    /**
     * 获取数据列表
     * @return array
     * @since 2024/11/22
     * @author 小树林
     */
    public function getList()
    {
        $param = request()->param();

        //是否为远程搜索查询
        $is_query = $param['_is_query'] ?? '';
        if (!empty($is_query)) {
            return parent::query($param);
        }

        // 查询条件
        $map = [];

        $giftNickname = getter($param,'giftNickname');
        if ($giftNickname) {
            $arr = Db::name("member")->where("nickname","like","%{$giftNickname}%")->column("id");

            $map[] = ['gift_user_id', 'in', $arr];
        }

        $beNickname = getter($param,'beNickname');
        if ($beNickname) {
            $arr = Db::name("member")->where("nickname","like","%{$beNickname}%")->column("id");

            $map[] = ['be_gift_user_id', 'in', $arr];
        }

        $field = '*';
        $with = [];
        $sort = '';

        $res = parent::getList($map, $field, $with, $sort); // TODO: Change the autogenerated stub
        if ($res['count'] != 0) {
            foreach ($res['data'] as &$v) {
                $v['giftNickname'] = Db::name("member")->where("id",$v['gift_user_id'])->value("nickname");
                $v['beNickname'] = Db::name("member")->where("id",$v['be_gift_user_id'])->value("nickname");
            }
        }
        return $res;
    }


}